// LegoLightSensor.cpp - Library for reading the Lego light sensor value.
// Created by Wongoo Lee.
// Released into the public domain.

#include "Arduino.h"
#include "LegoLightSensor.h"

LegoLightSensor::LegoLightSensor(int pin) {
  pin_ = pin;
}

int LegoLightSensor::read() {
  pinMode(pin_, OUTPUT);
  digitalWrite(pin_, HIGH);
  delayMicroseconds(LEGOLIGHTSENSOR_LED_ON_TIME);
  pinMode(pin_, INPUT);
  delayMicroseconds(LEGOLIGHTSENSOR_OFF_WAIT_TIME);
  return analogRead(pin_);
}

